package utils;

import java.util.HashMap;
import java.util.PriorityQueue;

class ValueComparator implements java.util.Comparator<HashMap<Integer, Integer>> {
    @Override
    public int compare(HashMap<Integer, Integer> o1, HashMap<Integer, Integer> o2) {
        Integer value1 = o1.values().iterator().next();
        Integer value2 = o2.values().iterator().next();
        return value2.compareTo(value1);
    }
}

public class HashPriorty {
    public static void main(String[] args) {
        HashMap<Integer, Integer> map1 = new HashMap<>();
        map1.put(1, 5);
        HashMap<Integer, Integer> map2 = new HashMap<>();
        map2.put(2, 3);
        HashMap<Integer, Integer> map3 = new HashMap<>();
        map3.put(3, 7);

        PriorityQueue<HashMap<Integer, Integer>> queue = new PriorityQueue<>(new ValueComparator());
        queue.add(map1);
        queue.add(map2);
        queue.add(map3);

        while (!queue.isEmpty()) {
            HashMap<Integer, Integer> map = queue.poll();
            System.out.println(map);
        }
    }
}